﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CodeAuto.Pages
{
    public partial class TableAdd : System.Web.UI.Page
    {
        public bool IsLogin = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.RegisterHyperLink.NavigateUrl = "/Pages/ProjectTables.aspx?docid=" + Request["docid"];
            if (Session["user"] != null)
            {
                IsLogin = true;
            }
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {

            DavidDB.ADO.DBManager db = new DavidDB.ADO.DBManager();
            Models.T_Table table = new Models.T_Table();
            table.Description = this.TextBox1.Text;
            table.ProjectId = Convert.ToInt32(Request.QueryString["docid"]);
            table.TableName = this.TableName.Text;
            int tableId = db.Insert(table);
            for (int i = 0; i < 50; i++)
            {
                if (!string.IsNullOrEmpty(Request["f" + i]))
                {
                    Models.T_Field field = new Models.T_Field();
                    field.Attr = Request["add" + i];
                    field.Field = Request["f" + i];
                    field.FieldName = Request["n" + i];
                    field.TableId = tableId;
                    db.Insert(field);
                }
            }

            db.Commit();
            db.Dispose();
            Response.Redirect("ProjectTables.aspx?docid=" + table.ProjectId);
        }
    }
}